package com.example.pinkcat.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.pinkcat.R;

import com.example.pinkcat.activity.api.getData.GetData;
import com.example.pinkcat.activity.changuserinfo.area;
import com.example.pinkcat.activity.changuserinfo.headimg;
import com.example.pinkcat.activity.pinkCatUser.userStaticMsg;
import com.rishabhharit.roundedimageview.RoundedImageView;

import java.util.Objects;

public class UserInfoChangePage extends AppCompatActivity {
    Context context=this;
    RoundedImageView head;
    TextView name;
    TextView sex;
    TextView birth;
    TextView area;
    TextView school;
    TextView id;
    TextView phone;
    TextView mail;


    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Objects.requireNonNull(getSupportActionBar()).hide();//去掉标题栏
        //        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
        setContentView(R.layout.activity_user_info_change_page);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }//深色信息栏
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);//允许此线程内发起网络请求

        head=findViewById(R.id.user_head);
        name=findViewById(R.id.user_name);
        sex=findViewById(R.id.user_sex);
        birth=findViewById(R.id.user_birth);
        area=findViewById(R.id.user_area);
        school=findViewById(R.id.user_school);
        id=findViewById(R.id.user_id);
        phone=findViewById(R.id.user_phone);
        mail=findViewById(R.id.user_mail);

        listen();
        setinfo();//设置信息
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (userStaticMsg.vip==1){
            name.setTextColor(getResources().getColor(R.color.pink));
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        GetData.get_setUserInfo(context, head, name, sex, birth, area, school, id, phone, mail);
        GetData.getUserinfo(context);//获取用户信息
    }

    void listen(){
        //返回监听
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });


        //修改跳转
        //头像
        findViewById(R.id.head_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, headimg.class));
            }
        });
        //地区
        findViewById(R.id.area_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.area.class));
            }
        });
        //出生日期
        findViewById(R.id.borth_date_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.birth.class));
            }
        });
        //邮箱
        findViewById(R.id.mail_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.email.class));
            }
        });
        //名称
        findViewById(R.id.name_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.name.class));
            }
        });
        //电话号码
        findViewById(R.id.phoneNumb_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"目前不支持修改",Toast.LENGTH_SHORT).show();
                //startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.phone.class));
            }
        });
        //id
        findViewById(R.id.pcid_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"目前不支持修改",Toast.LENGTH_SHORT).show();
                //startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.phone.class));
            }
        });
        //学校
        findViewById(R.id.school_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.school.class));
            }
        });
        //出生日期
        findViewById(R.id.sex_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context, com.example.pinkcat.activity.changuserinfo.sex.class));
            }
        });
    }

    void setinfo(){
        if (GetData.get_setUserInfo(context, head, name, sex, birth, area, school, id, phone, mail)){//用户未登录返回true
            Intent intent=new Intent(context, LoginRegisterPage.class);
            startActivity(intent);
        }
    }
}